import React from 'react';
import { WeaTools, WeaLeftRightLayout } from 'ecCom';

import './style/';
import MaterialLibLeft from './MaterialLibLeft';
import MaterialLibRight from './MaterialLibRight';

class MaterialLib extends React.Component {
    state = { visible: true, hasRight: false, dir: 'image/' };

    constructor(props) {
        super(props);
        this.setVisible = this.setVisible.bind(this);
        this.setDir = this.setDir.bind(this);
    }

    componentWillMount() {
        WeaTools.callApi('/api/portal/materialLib/getRightStatus', 'GET', {}).then((result) => {
            this.setState({ hasRight: result.right_status == 1 });
        });
    }

    render() {
        const { multiCheck, isShow } = this.props;
        const { visible, hasRight, dir } = this.state;

        return (
            visible ?
                <WeaLeftRightLayout ecId={`${this && this.props && this.props.ecId || ''}_WeaLeftRightLayout@bssxqj`}
                  leftWidth={260}
                  showLeft={true}
                  leftCom={<MaterialLibLeft ecId={`${this && this.props && this.props.ecId || ''}_MaterialLibLeft@30pmmh`} hasRight={hasRight} setDir={this.setDir} />}
                  children={<MaterialLibRight ecId={`${this && this.props && this.props.ecId || ''}_MaterialLibRight@pb3kc7`} ref="mlr" hasRight={hasRight} dir={dir} multiCheck={multiCheck} onLoading={this.props.onLoading} isShow={isShow} />}
                /> : ''
        );
    }

    setVisible(visible) {
        this.setState({ visible });
    }

    setDir(dir) {
        this.setState({ dir });
    }

    getCheckedFiles() {
        return this.refs.mlr.getCheckedFiles();
    }
}

export default MaterialLib;
